﻿@page
@model ViewDataModel
@{
    ViewData["Title"] = "View Items";
}

<form method="POST">
    <table class="itemlist">
        <caption>Item List</caption>
        <thead>
        <tr><th> </th><th>Id</th><th>Price</th><th>Description</th></tr>
        </thead>
        @foreach (var item in Model.Items)
        {
            <tr>
                @if (Model.Editing == item.Id)
                {
                    <td>
                        <button class="link" type="submit" asp-page-handler="Update" asp-route-id="@item.Id">Update</button>
                        <button class="link" type="submit" asp-page-handler="CancelUpdate">Cancel</button>
                    </td>
                    <td>@item.Id</td>
                    <td><input type="number" min="0" step="any" name="Price" value="@item.Price" /></td>
                    <td><input type="text" name="Description" value="@item.Description" /></td>
                }
                else
                {
                    <td>
                        <button class="link" type="submit" asp-page-handler="Edit" asp-route-id="@item.Id">Edit</button>
                        <button class="link" type="submit" asp-page-handler="Delete" asp-route-id="@item.Id">Delete</button>
                    </td>
                    <td>@item.Id</td>
                    <td>@item.Price</td>
                    <td>@item.Description</td>
                }
            </tr>
        }
    </table>
</form>
<a href="~/InsertItem">Add New Item</a>